a, res = input(), 0
if len(a) == 4:
    def check(c, bi):
        d = 1
        for j in range(2, c - 1):
            if c % j == 0: d = 0
        if d == 1 and c > bi: return c
        else: return bi
    m1, m2, m3, m4 = a[0], a[1], a[2], a[3]
    res = check(int(m1), res)
    res = check(int(m2), res)
    res = check(int(m3), res)
    res = check(int(m4), res)
    res = check(int(m1+m2), res)
    res = check(int(m2+m3), res)
    res = check(int(m3+m4), res)
    res = check(int(m1+m2+m3), res)
    res = check(int(m2+m3+m4), res)
    res = check(int(m1+m2+m3+m4), res)
print(res)
    
